unit SmallStruct.View.TSSDataView;

interface

uses
  Windows,
  Messages,
  SysUtils,
  Variants,
  Classes,
  Graphics,
  Controls,
  Forms,
  SmallStruct.View.TSSView,
  DB,
  SmallStruct.Model,
  cxContainer,
  cxEdit,
  cxControls,
  cxTextEdit,
  cxMaskEdit,
  cxDropDownEdit,
  cxLookupEdit,
  cxDBLookupEdit,
  cxDBLookupComboBox,
  StdCtrls,
  Mask,
  DBCtrls,
  ExtCtrls,
  cxMemo,
  cxDBEdit,
  cxCalendar,
  RzPanel,
  RzBckgnd,
  SmallStruct.View,
  ComCtrls,
  RzDTP,
  RzDBDTP;

type
  TSSDataView = class(TSSView, ISSDataView)
  public
    procedure InitDataSource; virtual;
  protected
    function GetDataSource(const AModelName: string): TDataSource;
    function QueryDataModel(const AModelName: string): ISSDataModel;
    procedure SetDataSource(const PrimaryModelName, FieldName, ForeignModelName, KeyFieldName, DisplayFieldName: string; LookupComboBox: TcxDBLookupComboBox); overload;
    procedure SetDataSource(const PrimaryModelName, FieldName: string; DBMemo: TcxDBMemo); overload;
    procedure SetDataSource(const PrimaryModelName, FieldName: string; DBDateEdit: TcxDBDateEdit); overload;
    procedure SetDataSource(const PrimaryModelName, FieldName: string; DBEdit: TcxDBTextEdit); overload;
    procedure SetDataSource(DataSource: TDataSource; const FieldName, ForeignModelName, KeyFieldName, DisplayFieldName: string; LookupComboBox: TcxDBLookupComboBox); overload;
    procedure SetDataSource(DataSource: TDataSource; const FieldName: string; DBMemo: TcxDBMemo); overload;
    procedure SetDataSource(DataSource: TDataSource; const FieldName: string; DBEdit: TcxDBTextEdit); overload;
  end;

implementation

uses dialogs;

{$R *.dfm}

{ TSSDataView }

function TSSDataView.GetDataSource(const AModelName: string): TDataSource;
begin
  Result := QueryDataModel(AModelName).GetDataSource;
end;

procedure TSSDataView.InitDataSource;
begin

end;

function TSSDataView.QueryDataModel(const AModelName: string): ISSDataModel;
begin
  Result := QueryModel(AModelName) as ISSDataModel;
end;

procedure TSSDataView.SetDataSource(DataSource: TDataSource; const FieldName: string; DBMemo: TcxDBMemo);
begin
  DBMemo.DataBinding.DataSource := DataSource;
  DBMemo.DataBinding.DataField := FieldName;
  DBMemo.Style.StyleController := _EditStyleController;
end;

procedure TSSDataView.SetDataSource(DataSource: TDataSource; const FieldName, ForeignModelName, KeyFieldName, DisplayFieldName: string; LookupComboBox: TcxDBLookupComboBox);
begin
  LookupComboBox.DataBinding.DataSource := DataSource;
  LookupComboBox.DataBinding.DataField := FieldName;
  LookupComboBox.Properties.ListSource := GetDataSource(ForeignModelName);
  LookupComboBox.Properties.ListFieldNames := DisplayFieldName;
  LookupComboBox.Properties.KeyFieldNames := KeyFieldName;
  LookupComboBox.Style.LookAndFeel.NativeStyle := True;
  LookupComboBox.Style.StyleController := _EditStyleController;
end;

procedure TSSDataView.SetDataSource(DataSource: TDataSource; const FieldName: string; DBEdit: TcxDBTextEdit);
begin
  DBEdit.DataBinding.DataSource := DataSource;
  DBEdit.DataBinding.DataField := FieldName;
  DBEdit.Style.StyleController := _EditStyleController;
end;

procedure TSSDataView.SetDataSource(const PrimaryModelName, FieldName: string; DBMemo: TcxDBMemo);
begin
  DBMemo.DataBinding.DataSource := GetDataSource(PrimaryModelName);
  DBMemo.DataBinding.DataField := FieldName;
  DBMemo.Style.StyleController := _EditStyleController;
end;

procedure TSSDataView.SetDataSource(const PrimaryModelName, FieldName, ForeignModelName, KeyFieldName, DisplayFieldName: string; LookupComboBox: TcxDBLookupComboBox);
begin
  LookupComboBox.DataBinding.DataSource := GetDataSource(PrimaryModelName);
  LookupComboBox.DataBinding.DataField := FieldName;
  LookupComboBox.Properties.ListSource := GetDataSource(ForeignModelName);
  LookupComboBox.Properties.ListFieldNames := DisplayFieldName;
  LookupComboBox.Properties.KeyFieldNames := KeyFieldName;
  LookupComboBox.Style.LookAndFeel.NativeStyle := True;
  LookupComboBox.Style.StyleController := _EditStyleController;
end;

procedure TSSDataView.SetDataSource(const PrimaryModelName, FieldName: string; DBEdit: TcxDBTextEdit);
begin
  DBEdit.DataBinding.DataSource := GetDataSource(PrimaryModelName);
  DBEdit.DataBinding.DataField := FieldName;
  DBEdit.Style.StyleController := _EditStyleController;
end;

procedure TSSDataView.SetDataSource(const PrimaryModelName, FieldName: string; DBDateEdit: TcxDBDateEdit);
begin
  DBDateEdit.DataBinding.DataSource := GetDataSource(PrimaryModelName);
  DBDateEdit.DataBinding.DataField := FieldName;
  DBDateEdit.Style.StyleController := _EditStyleController;
end;

end.
